#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jan  1 22:36:39 2022

@author: liqingsimac
"""

###############################################
##黎曼-斯蒂尔杰斯积分
import numpy as np
import matplotlib.pyplot as plt

x1=np.array([0,0])
y1=np.array([0,1/3])
x2=np.array([1,1])
y2=np.array([0,2/3])

fig=plt.figure()
ax=fig.add_subplot(121)

ax.hlines(y=0,xmin=-0.5,xmax=1.5)
#ax.vlines(x=0,ymin=0,ymax=1)

ax.plot(x1,y1,'-')
ax.plot(x2,y2,'-')

ax.set_xlabel(r'$x$')
ax.set_ylabel(r'probability $p(x)$')
ax.set_xticks([-0.5,0,0.5,1,1.5])
ax.set_yticks([0,1/3,2/3,1])

#---------------------------------
x3=np.array([-0.5,0])
y3=np.array([0,0])
x4=np.array([0,1])
y4=np.array([1/3,1/3])
x5=np.array([1,1.5])
y5=np.array([1,1])

bx=fig.add_subplot(122)

#bx.hlines(y=0,xmin=-0.2,xmax=1.2)
#bx.vlines(x=0,ymin=0,ymax=1)

bx.plot(x3,y3,'-')
bx.plot(x4,y4,'-')
bx.plot(x5,y5,'-')
bx.set_xticks([-0.5,0,0.5,1,1.5])
bx.set_yticks([0,1/3,2/3,1])

bx.set_xlabel(r'$x$')
bx.set_ylabel(r'distribution function $F(x)$')

fig.tight_layout(w_pad=2)
#fig.savefig('riemann-stieltjes.png')

